/*
 * @Description: 
 * @Autor: wangwangwang
 * @Date: 2021-06-25 11:37:28
 * @LastEditors: wangwangwang
 * @LastEditTime: 2021-06-25 12:05:10
 */
import { queryPage2 } from "@/api/basedata/organization"; // 组织新接口
import { queryPage as userQueryPage, queryjobPage } from "@/api/basedata/user";
import { queryPage } from "@/api/basedata/role";

const state = {
  orgList: '',
  userList: '',
  positionData: '',
  rolesData: '',
}

const mutations = {
  SET_ORG: (state, data) => {
    state.orgList = data
  },
  SET_USER: (state, data) => {
    state.userList = data
  },
  SET_POSITION: (state, data) => {
    state.positionData = data
  },
  SET_ROLES: (state, data) => {
    state.rolesData = data
  },
}

const actions = {
  getorg({ commit }) {
    return new Promise ((resolve) => {
      const params = {
        page: 1,
        pageSize: 10000,
      };
      queryPage2(params).then((res) => {
        if (res.code === 1001) {
          commit('SET_ORG', res.data.data);
          resolve(res.data.data);
        }
      });
    })
  },
  getuser({ commit }) {
    return new Promise((resolve) => {
      const params = {
        page: 1,
        pageSize: 10000,
        userEentrance: "entrance_manager",
      };
      userQueryPage(params).then((res) => {
        if (res.code === 1001) {
          commit('SET_USER', res.data.data);
          resolve(res.data.data);
        }
      })
    })
  },
  getposition({ commit }) {
    return new Promise((resolve) => {
      const data = {
        page: 1,
        pageSize: 1000,
      };
      queryjobPage(data).then((res) => {
        if (res.code === 1001) {
          commit('SET_POSITION', res.data.data);
          resolve(res.data.data);
        }
      });
    })
  },
  getroles ({ commit }) {
    return new Promise((resolve) => {
      const data = {
        page: 1,
        pageSize: 1000,
        userEentrance: "entrance_manager",
      };
      queryPage(data).then((res) => {
        if (res.code === 1001) {
          commit('SET_ROLES', res.data.data);
          resolve(res.data.data);
        }
      });
    })
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
}
